package com.cyandpos.pad.common.netmanager;

import android.text.TextUtils;
import android.util.Log;


import com.cyandpos.pad.common.commondata.ErpCommonData;
import com.cyandpos.pad.common.commondata.Urls;
import com.cyandpos.pad.cateringformat.morefunction.bean.OrderfoodInput;
import com.cyandpos.pad.http.OkHttpUtils;
import com.cyandpos.pad.login.configs.GetConfigs;
import com.cyandpos.pad.netdata.P_Commit;
import com.cyandpos.pad.netdata.P_Login;
import com.cyandpos.pad.offline.bean.P_GetOffline;
import com.cyandpos.pad.offline.offlinedb.OfflineManager;
import com.cyandpos.pad.offline.upload.TicketOffline;
import com.cyandpos.pad.posdata.CardCouponItem;
import com.cyandpos.pad.posdata.CashCardItem;
import com.cyandpos.pad.posdata.CodeCoupon;
import com.cyandpos.pad.posdata.CodedCouponItem;
import com.cyandpos.pad.posdata.ConsumeCrmPayData;
import com.cyandpos.pad.posdata.CzkCardItem;
import com.cyandpos.pad.posdata.Goods;
import com.cyandpos.pad.posdata.Machine;
import com.cyandpos.pad.posdata.MoneyBuyCentData;
import com.cyandpos.pad.posdata.POS_JHRequest;
import com.cyandpos.pad.posdata.Payment;
import com.cyandpos.pad.posdata.PosO2ORequest;
import com.cyandpos.pad.posdata.PrepareRefundData;
import com.cyandpos.pad.posdata.PromationoodInfo;
import com.cyandpos.pad.posdata.QueryGoodParam;
import com.cyandpos.pad.posdata.QueryMemberReq;
import com.cyandpos.pad.posdata.QueryMemberRequest;
import com.cyandpos.pad.posdata.QueryOrderReq;
import com.cyandpos.pad.posdata.TicketInfo;
import com.cyandpos.pad.posdata.YhkCardItem;
import com.cyandpos.pad.posdata.YhqCardItem;
import com.cyandpos.pad.utils.CommonUtils;
import com.cyandpos.pad.utils.DateUtils;
import com.cyandpos.pad.utils.MoneyUtils;
import com.cyandpos.pad.utils.PayUtil;
import com.cyandpos.pad.utils.log.MessageLog;
import com.cyandpos.pad.utils.log.LogUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;


/**
 * Created by Yangzw on 2017/2/26.
 * 网络请求操作的方法
 */
public class PosHttpManager {
    private static final Map<String, Object> baseMap;
    private static Map<String, Object> map;

    static {
        baseMap = new HashMap<String, Object>();
        baseMap.put("sys_key",ErpCommonData.key);
        baseMap.put("timestamp", DateUtils.getCurrentTime());
        baseMap.put("token","");
        baseMap.put("format","json");
        baseMap.put("version","1.0");
    }

    public static void updateBaseConfigInfo() {
        baseMap.put("sys_key",ErpCommonData.key);
        baseMap.put("token","");
        baseMap.put("timestamp", DateUtils.getCurrentTime());
        baseMap.put("format","json");
        baseMap.put("version","1.0");
//        initInterceptor();
    }

//    private static void initInterceptor() {
//        OkHttpUtils.INTERCEPTORS.clear();
//        DebugInterceptor interceptorLogin = new DebugInterceptor("logintest", R.raw.logintest);
//        OkHttpUtils.addInterceptor(interceptorLogin);
//    }

    /**
     * 登陆
     *
     * @param machine  款台信息
     * @param callback
     * 当调用某个类的静态方法时
     */
    public static void LoginHttpEexcute(Machine machine, String mac, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        baseMap.put("timestamp", DateUtils.getCurrentTime());
        map.putAll(baseMap);
        P_Login pLogin = new P_Login();
        pLogin.setPersonCode(machine.getPersonCode());
        pLogin.setPassword(machine.getPassword());
        pLogin.setStoreCode(ErpCommonData.storeCode);
        pLogin.setMac(mac);
        pLogin.setSktno(ErpCommonData.sktno);
        pLogin.setAnthCode("");

        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("personCode",pLogin.getPersonCode());
        newMap.put("password",pLogin.getPassword());
        newMap.put("storeCode",pLogin.getStoreCode());
        newMap.put("mac",pLogin.getMac());
        newMap.put("sktno",pLogin.getSktno());
        newMap.put("anthCode",pLogin.getAnthCode() +"");
        newMap.put("ddly","1");
        String sortJsonStr = CommonUtils.sortStrNewJsonStr(newMap);
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url ="";
        if(ErpCommonData.proType == ErpCommonData.DEMO){
            LogUtils.e("LOGIN","登录demo");
            url = Urls.getMethodUrl("logintest");
        }else{
            url = Urls.getMethodUrl("common/login");
        }
        if(ErpCommonData.isOffline) {
            OfflineManager.login(newMap, callback);
        }else{
            OkHttpUtils.post(url, map, callback);
        }
    }

    /**
     * 状态监控
     */
    public static void SktGxsj(OkHttpUtils.ResultCallback callback){
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("storeCode",ErpCommonData.storeCode);
        newMap.put("sktno",ErpCommonData.sktno);
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        OkHttpUtils.post(Urls.getMethodUrl("common/updatesktstatus"), map, callback);

    }
    /**
     * 登出
     */
    public static void LoginOut(OkHttpUtils.ResultCallback callback){
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("storeCode",ErpCommonData.storeCode);
        newMap.put("sktno",ErpCommonData.sktno);
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("common/loginout");
        LogUtils.d("LoginHttpEexcute", url);
        OkHttpUtils.post(url, map, callback);
    }

        /**
     * 创建订单号
     * @param orderNo
     * @param callback
     */

    public static void CreateSaleId(String orderNo,String tableNo,String tablePerson, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("storeCode",ErpCommonData.storeCode);
        newMap.put("ddly","1");
        newMap.put("ddlx","0");
        if (orderNo.equals("1"))//orderNo =1 代表负数退货
            newMap.put("ddlx","1");
        if (ErpCommonData.ticketInfo.isDJD())
            newMap.put("orderFunction","1");
        newMap.put("sktno",ErpCommonData.sktno);
        newMap.put("shopId",ErpCommonData.shopId);
        newMap.put("tableNo",tableNo);
        newMap.put("mealsCount",tablePerson);
        newMap.put("operatorCode",ErpCommonData.loadConfig.getCashierCode());
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
         Log.i("TAG----创建订单入参",sortJsonStr.toString());

        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("order/create");
        if(ErpCommonData.isOffline) {
            OfflineManager.createOrder(newMap, callback);
        }else{
            OkHttpUtils.post(url, map, callback);
        }
    }


    /**
     * 查营业员
     * @param personCode
     * @param callback
     */
    public static void QueryPersonExecute(String personCode, String orderNo,OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("storeCode",ErpCommonData.storeCode);
        if (personCode.length() < GetConfigs.getPersonCodeLength()){//自动补0
            personCode = CommonUtils.autoAddZero(personCode, GetConfigs.getPersonCodeLength());
        }
        newMap.put("personCode",personCode);
        newMap.put("needGoodsList",1);
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("common/getperson");
        if(ErpCommonData.isOffline) {
            newMap.put("orderNo",orderNo);
            OfflineManager.QueryPerson(newMap, callback);
        }else{
            OkHttpUtils.post(url, map, callback);
        }
    }

    /**
     * 查商品
     * @param content 商品请求参数
     * @param callback
     */

    public static void QueryGoodsInfoExecute(QueryGoodParam content, TicketInfo ticketInfo, int subInx, OkHttpUtils.ResultCallback callback) {
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("ddly","1");
            if (ErpCommonData.ticketInfo.isFSTH()){
                Params_json.put("ddlx","1");//“0”：销售“1”：退货
            }else {
                Params_json.put("ddlx","0");//“0”：销售“1”：退货
            }
            if (ErpCommonData.ticketInfo.isDJD()){
                Params_json.put("orderFunction","1");//“0”：销售“1”：退货
            }
            Params_json.put("sktno",ErpCommonData.sktno);
            Params_json.put("orderNo",ticketInfo.getOrderNo());
            Params_json.put("shopId",ErpCommonData.shopId);
            if(ticketInfo.getSubTickets().get(subInx).getPersonInfo()!=null) {
                Params_json.put("personCode", ticketInfo.getSubTickets().get(subInx).getPersonInfo().getPersonCode());
            }else{
                Params_json.put("personCode", ticketInfo.getCasherInfo().getPersonCode());
            }
            Params_json.put("ticktInx",subInx);
            Params_json.put("permit_zg",ErpCommonData.proType);
            Params_json.put("goodsPrice", content.getGoodsPrice());
            if(ticketInfo.isFSTH()&&!content.getCount().contains("-")){
                if("0".equals(content.getCount())){
                    Params_json.put("count", "0");
                }else {
                    Params_json.put("count", "-1");
                }
            }else if(ticketInfo.isFSTH()){
                Params_json.put("count", content.getCount());
            }
            else {
                Params_json.put("count", content.getCount());
            }
            Params_json.put("barcode",CommonUtils.autoAddZero(content.getBarcode(), GetConfigs.getGoodsCodeLength()));
            Params_json.put("goodsGuid",content.getGoodsGuid());
            Params_json.put("tasteId",content.getTasteId());
            Params_json.put("desc",content.getDesc());
            Params_json.put("goodsId",content.getGoodsId());
            Params_json.put("tableNo",ticketInfo.getTableNo());
            Params_json.put("stamp", content.getStamp());
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Log.i("TAG-----查商品入参",sortJsonStr.toString());
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        if(ErpCommonData.isOffline) {
            OfflineManager.QueryGoods(Params_json, callback);
        }else{
            OkHttpUtils.post(Urls.getMethodUrl("order/addgoods"), map, callback);
        }
    }

    /**
     * 管理卡验证
     *
     * @param managerNo 管理卡号
     * @param callback
     */
    public static void managerYZHttpEexcute(String orderNo,String managerNo, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("storeCode",ErpCommonData.storeCode);
        if (!TextUtils.isEmpty(orderNo)){
            newMap.put("orderNo",orderNo);
        }
        newMap.put("cardNo",managerNo);
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("common/getglk");
        OkHttpUtils.post(url, map, callback);
    }

    /**
     * 查询订单
     * @param req
     * @param callback
     */
    public static void QueryOrderInfoEexcute(QueryOrderReq req, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("sktno",req.getSktno());
            Params_json.put("orderNo",req.getOrderNo());
           // Params_json.put("shopId",ErpCommonData.shopId);
            Params_json.put("tableNo",req.getTableNo());
            Params_json.put("jlbh",req.getJlbh());
            Params_json.put("status",req.getStatus());
            Params_json.put("ddly","1");
            Params_json.put("queryHistoryData",req.isQueryHistoryData());
            Params_json.put("beginTime",req.getBeginTime());
            Params_json.put("endTime",req.getEndTime());
            Params_json.put("pageNo",req.getPageNo());
            Params_json.put("pageSize",req.getPageSize());

            if (req.getOrderFunction().equals("1")){
                Params_json.put("orderFunction",req.getOrderFunction());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);
        Log.i("TAG----订单查询入参：",sortJsonStr.toString());
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("order/query");
        if(ErpCommonData.isOffline) {
            OfflineManager.QueryOrderInfoEexcute(Params_json, callback);
        }else {
            OkHttpUtils.post(url, map, callback);
        }
    }



    //退货准备接口
    public static void backUpLoadGoods2CrmRequestParam(PrepareRefundData backUploadReq, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("storeCode",backUploadReq.getStoreCode());
        newMap.put("ddly",backUploadReq.getDdly());
        newMap.put("ddlx",backUploadReq.getDdlx());
        newMap.put("sktno",backUploadReq.getSktno());
        newMap.put("operatorCode",backUploadReq.getOperatorCode());
        newMap.put("oldOrderNo",backUploadReq.getOldOrderNo());
        newMap.put("goodsList",backUploadReq.getGoodsList());
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("order/backgoodsprepare");
        OkHttpUtils.post(url, map, callback);
    }

    private static ArrayList<Goods> handBackGoods(TicketInfo oldTicketInfo){
        ArrayList<Goods> backGoods = new ArrayList<>();
        int goodInx = 0;
        for (Goods goods :  oldTicketInfo.getSubTickets().get(0).getGoodsList()){
            if (Integer.valueOf(goods.getRefundCount())>0){
                Goods backUpLoadGoods = new Goods();
                backUpLoadGoods.setInx(goods.getInx());
                backUpLoadGoods.setGoodsGuid(goods.getGoodsGuid());
                backUpLoadGoods.setBarCode(goods.getBarCode());
                backUpLoadGoods.setCode(goods.getCode());
                backUpLoadGoods.setName(goods.getName());
                backUpLoadGoods.setId(goods.getId()+"");
                backUpLoadGoods.setUnit(goods.getUnit());
                backUpLoadGoods.setPrice(goods.getPrice());
                backUpLoadGoods.setSaleCount(goods.getRefundCount());
               /* int refundCout=Integer.valueOf(goods.getRefundCount());
                int price=MoneyUtils.getMoneyInt(goods.getPrice());
                int discount=MoneyUtils.getMoneyInt(goods.getDiscount())/Integer.valueOf(goods.getSaleCount());
                int preferentialMoney=MoneyUtils.getMoneyInt(goods.getPreferentialMoney());*/
                backUpLoadGoods.setSaleMoney(MoneyUtils.getMoneyStr(Integer.valueOf(goods.getRefundCount())*(MoneyUtils.getMoneyInt(goods.getPrice())-MoneyUtils.getMoneyInt(goods.getDiscount())/Integer.valueOf(goods.getSaleCount())-MoneyUtils.getMoneyInt(goods.getPreferentialMoney()))));
                backUpLoadGoods.setDiscount(MoneyUtils.getMoneyStr(Integer.valueOf(goods.getRefundCount())*(MoneyUtils.getMoneyInt(goods.getDiscount())/Integer.valueOf(goods.getSaleCount())-MoneyUtils.getMoneyInt(goods.getPreferentialMoney()))));
                backUpLoadGoods.setPreferentialMoney(goods.getPreferentialMoney());
                backUpLoadGoods.setTicktInx(goods.getTicktInx()+"");
                backUpLoadGoods.setTicktGoodsInx(goods.getTicktGoodsInx()+"");
                backGoods.add(backUpLoadGoods);
            }

        }
        return backGoods;
    }

    /**
     * 前台折扣
     * @param disType  折扣类型
     * @param money  折扣金额(折扣率)
     * @param goods   单品
     * @param orderNo  订单号
     * @param isSingle  是否单品折扣
     * @param callback
     */
    public static void FrontDiscount(String disType, String money, Goods goods, String orderNo,boolean isSingle, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("ddly","1");
            Params_json.put("ddlx","0");//“0”：销售“1”：退货
            Params_json.put("orderNo",orderNo);
            Params_json.put("sktno",ErpCommonData.sktno);
            if (isSingle){
                Params_json.put("goodsGuid",goods.getGoodsGuid());
            }
            Params_json.put("discountType",disType);//“0”：折扣率“1”：折扣金额
            Params_json.put("discount",money);//8为8这
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("order/frontdiscount");
        if(ErpCommonData.isOffline) {
            OfflineManager.frontDiscount(disType,money,goods,orderNo, callback);
        }else {
            OkHttpUtils.post(url, map, callback);
        }
    }


      /**
     * 添加会员到订单
     * @param requestParam
     * @param callback
     */

    public static void QueryMemberExecute(QueryMemberReq requestParam, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("ddly","1");
            Params_json.put("ddlx","0");
            Params_json.put("sktno",ErpCommonData.sktno);
            Params_json.put("orderNo",requestParam.getOrderNo());
            Params_json.put("cardNo",requestParam.getCardNo());
            Params_json.put("condType",requestParam.getCondType());
            Params_json.put("isNew",true);//True：添加会员 False：取消会员
            Params_json.put("isCreate",requestParam.getIsCreate());//0：添加会员 1：注册会员
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        if(ErpCommonData.isOffline){
            OfflineManager.queryMember(Params_json,callback);
        }else {
            OkHttpUtils.post(Urls.getMethodUrl("order/addmember"), map, callback);
        }
    }
        /**
     * 取消订单号
     * @param orderNo
     * @param callback
     */
    public static void cancelOrder(String orderNo, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("ddly","1");
            Params_json.put("ddlx","0");
            Params_json.put("sktno",ErpCommonData.sktno);
            Params_json.put("orderNo",orderNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("order/cancel");
        OkHttpUtils.post(url, map, callback);
    }


    /**
     * Derek
     * 准备付款
     *
     * @param ticketInfo
     * @param callback
     */
    public static void PreparePay(TicketInfo ticketInfo, boolean isPromotion, List<PromationoodInfo> exchangeGoodBillInfoList, List<PromationoodInfo> giftGoodsBillList, int promotionGoodsSelectSign,OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("ddly","1");
            if (ticketInfo.isFSTH()){
                Params_json.put("ddlx","1");
            }else {
                Params_json.put("ddlx","0");
            }
            if (ticketInfo.isDJD())
            {
                Params_json.put("orderFunction","1");
                Params_json.put("phone",ticketInfo.getDepositOrderInfo().getPhone());
                Params_json.put("djdAmount",ticketInfo.getDepositOrderInfo().getDjdAmount());
                Params_json.put("transferDate",ticketInfo.getDepositOrderInfo().getTransferDate());
            }
            Params_json.put("exchangeGoodsInfoList",exchangeGoodBillInfoList);
            Params_json.put("giftGoodsList",giftGoodsBillList);
            Params_json.put("promotionGoodsSelectSign", promotionGoodsSelectSign + "");

            Params_json.put("sktno",ErpCommonData.sktno);
            Params_json.put("orderNo",ticketInfo.getOrderNo());
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        Log.i("TAG---- 准备付款入参",sortJsonStr.toString());
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        if(ErpCommonData.isOffline) {
            OfflineManager.PreparePay(Params_json, callback);
        }else{
            if(isPromotion)
                OkHttpUtils.post(Urls.getMethodUrl("order/preparecalculatepromotion"), map, callback);
            else
                OkHttpUtils.post(Urls.getMethodUrl("order/prepare"), map, callback);
        }
    }

    /*
    *   付款界面 同步付款
    * */
    public static void AddPay(String orderNo, List<Payment> payItems , int saleType, boolean clearFlag, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("ddlx",saleType+"");
        newMap.put("ddly","1");
        newMap.put("orderNo",orderNo);
        newMap.put("sktno",ErpCommonData.sktno);
        newMap.put("storeCode",ErpCommonData.storeCode);
        newMap.put("payList",payItems);
        newMap.put("clearPay",clearFlag);
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("order/addpay");
        LogUtils.d("SynchronizationPay", url);
        if(ErpCommonData.isOffline) {
            OfflineManager.addPay(newMap, callback);
        }else {
            OkHttpUtils.post(url, map, callback);
        }

    }

    /**
     * 提交交易
     * @param ticketInfo
     * @param isCancelAfterSwipe  true 取消返券后刷卡
     * @param callback
     */
    public static void CommitPay(TicketInfo ticketInfo, boolean isCancelAfterSwipe,OkHttpUtils.ResultCallback callback) {
        map = new HashMap<>();
        map.putAll(baseMap);

        P_Commit payCommitData = new P_Commit();
        payCommitData.setDdly("1");//
        payCommitData.setDdlx(ticketInfo.getOldOrderNo()!=null && ticketInfo.getOldOrderNo().length()>0? "1": "0");
        payCommitData.setOrderNo(ticketInfo.getOrderNo());
        payCommitData.setSktno(ErpCommonData.sktno);
        payCommitData.setStoreCode(ErpCommonData.storeCode);

        //储值卡
        if(ticketInfo.getCashCardList()!=null && ticketInfo.getCashCardList().size()>0){
            for (CashCardItem item:ticketInfo.getCashCardList()){
                CzkCardItem czkCardItem=new CzkCardItem();
                czkCardItem.setCardNo(item.getCardNo());
                czkCardItem.setPayCode(item.getPayCode());
                czkCardItem.setPayType(item.getPayType());
                if(PayUtil.isReturnedTrade(ticketInfo))
                    czkCardItem.setAmount("-" + MoneyUtils.getMoneyStr(Math.abs(item.getmMoney())));
                else
                    czkCardItem.setAmount(MoneyUtils.getMoneyStr(Math.abs(item.getmMoney())));
                czkCardItem.setCardId(item.getCardId());
                czkCardItem.setBalance(MoneyUtils.getMoneyStr(item.getmLeft()));
                payCommitData.getCzkCard().add(czkCardItem);
            }
        }

        if(!PayUtil.isReturnedTrade(ticketInfo)){//退货交易不赋值YhqCard()
            //卡券
            if(ticketInfo.getCardCouponList()!=null && ticketInfo.getCardCouponList().size()>0){
                for (CardCouponItem item:ticketInfo.getCardCouponList()){
                    YhqCardItem cardItem=new YhqCardItem();
                    for(Payment p :ErpCommonData.loadConfig.getPayList()){
                        if(p.getYhqId() == item.getCouponType()){
                            cardItem.setPayCode(p.getPayCode() +"");
                            cardItem.setPayType(p.getPayType());
                            break;
                        }
                    }
                    cardItem.setCardId(item.getCardId());
                    cardItem.setCardCode(item.getCardCode());
                    cardItem.setUsedMoney(MoneyUtils.getMoneyStr(item.getUsedMoney()));
                    cardItem.setCouponType(item.getCouponType());
                    cardItem.setBalance(MoneyUtils.getMoneyStr(item.getBalance()));
                    payCommitData.getYhqCard().add(cardItem);
                }
            }



            //编码券
            if(ticketInfo.getCodedCouponList()!=null && ticketInfo.getCodedCouponList().size()>0){
                for (CodeCoupon item:ticketInfo.getCodedCouponList()){
                    CodedCouponItem cardItem=new CodedCouponItem();
                    cardItem.setCouponCode(item.getCouponCode());
                    cardItem.setAmount(MoneyUtils.getMoneyStr(item.getUsedMoney()));
                    for(Payment p :ErpCommonData.loadConfig.getPayList()){
                        if(p.getYhqId() == item.getCouponType()){
                            cardItem.setPayCode(p.getPayCode() +"");
                            cardItem.setPayType(p.getPayType());
                            break;
                        }
                    }
                    payCommitData.getBmqCard().add(cardItem);
                }
            }

        }


        if(ticketInfo.getPayList()!=null && ticketInfo.getPayList().size()>0){
            for(Payment pay :ticketInfo.getPayList()){
                if(pay.getPayType()==Payment.SKFS_WX || pay.getPayType()==Payment.SKFS_ZFB
                        || pay.getPayType() == Payment.SKFS_NORMAL
                        || pay.getPayType() == Payment.SKFS_YHK
                ){
                    Payment payItem = new Payment();
                    payItem.setPayAmount(pay.getPayAmount());
                    payItem.setPayCode(pay.getPayCode());
                    payItem.setPayType(pay.getPayType());
                    payCommitData.getPayList().add(payItem);
                }
            }
        }
        if(ticketInfo.getBankCardList()!=null && ticketInfo.getBankCardList().size()>0){
            for(YhkCardItem item :ErpCommonData.ticketInfo.getBankCardList())
            {
                payCommitData.getYhkCard().add(item);
            }
        }



        if(isCancelAfterSwipe){
            payCommitData.setMemberIdToGrantVoucher(-100 +"");
        }else{
            if(ticketInfo.getMemberInfo()!=null && ticketInfo.getMemberInfo().getMemberCardId()>0){//会员交易
                payCommitData.setMemberIdToGrantVoucher(ticketInfo.getMemberInfo().getMemberCardId() +"");
            }else{
                if(ticketInfo.getOfferCouponVipId()>0){//后刷卡
                    payCommitData.setMemberIdToGrantVoucher(ticketInfo.getOfferCouponVipId()+"");
                }else{
                    payCommitData.setMemberIdToGrantVoucher("");
                }
            }
        }

        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("ddlx",payCommitData.getDdlx());
        newMap.put("orderNo",payCommitData.getOrderNo());
        newMap.put("storeCode",payCommitData.getStoreCode());
        newMap.put("ddly",payCommitData.getDdly());
        newMap.put("sktno",payCommitData.getSktno());
        newMap.put("memberIdToGrantVoucher",payCommitData.getMemberIdToGrantVoucher() +"");
        newMap.put("czkCard",payCommitData.getCzkCard());
        newMap.put("yhqCard",payCommitData.getYhqCard());
        newMap.put("bmqCard",payCommitData.getBmqCard());
        newMap.put("payList",payCommitData.getPayList());
        newMap.put("yhkCard",payCommitData.getYhkCard());
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("order/commit");
        LogUtils.d("SynchronizationPay", url);
        if(ErpCommonData.isOffline) {
            OfflineManager.commitPay(newMap, callback);
        }else {
            OkHttpUtils.post(url, map, callback);
        }

    }

    /**
     * 返券后刷卡
     * @param requestParam
     * @param callback
     */
    public static void GetVipCardToGrantVoucher(QueryMemberRequest requestParam, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("condType",requestParam.getCondType());
        newMap.put("condValue",requestParam.getCondValue());
        newMap.put("verifyCode",requestParam.getVerifyCode());
        newMap.put("password",requestParam.getPassword());
        newMap.put("codedCouponCode",requestParam.getCodedCouponCode());
        newMap.put("codedCouponType",requestParam.getCodedCouponType() +"");
        newMap.put("serverBillId",requestParam.getServerBillId());
        newMap.put("cardCodeToCheck",requestParam.getCardCodeToCheck());
        newMap.put("sktno",requestParam.getSktno());
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        OkHttpUtils.post(Urls.getMethodUrl("crm/GetVipCardToGrantVoucher"), map, callback);
    }

    /**
     * O2O交易请求
     * @param posO2oRequest
     * @param callback
     */
    public static void O2OTraceRequestExecute(PosO2ORequest posO2oRequest, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("orderno",posO2oRequest.getOrderno());
        newMap.put("appCode",posO2oRequest.getAppCode());
        newMap.put("appType",posO2oRequest.getAppType());
        newMap.put("posId",posO2oRequest.getPosId());
        newMap.put("receiptNo",posO2oRequest.getReceiptNo());
        newMap.put("mch_Id",posO2oRequest.getMch_Id() +"");
        newMap.put("totalFee",posO2oRequest.getTotalFee());
        newMap.put("buyerCode",posO2oRequest.getBuyerCode());
        newMap.put("guid",posO2oRequest.getGuid());
        newMap.put("personId",posO2oRequest.getPersonId());
        newMap.put("attach",posO2oRequest.getAttach());
        newMap.put("outTradeNo",posO2oRequest.getOutTradeNo());
        newMap.put("outTradeNo_Old",posO2oRequest.getOutTradeNo_Old());
        newMap.put("transactionId_Old",posO2oRequest.getTransactionId_Old());
        newMap.put("oldPosId",posO2oRequest.getOldPosId());
        newMap.put("totalFee_Old",posO2oRequest.getTotalFee_Old());
        newMap.put("orderTime_Old",posO2oRequest.getOrderTime_Old());
        newMap.put("payCode",posO2oRequest.getPayCode());
        newMap.put("param3",posO2oRequest.getParam3());
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        OkHttpUtils.post(Urls.getMethodUrl("o2o/PosPay_o2o"), map, callback);
    }

    /**
     * Derek
     * 查会员信息（会员查询模块）
     *
     * @param requestParam
     * @param callback
     */

    public static void QueryMemberInfoExecute(QueryMemberRequest requestParam, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("condType",requestParam.getCondType());
            Params_json.put("condValue",requestParam.getCondValue());
            Params_json.put("sktno",ErpCommonData.sktno);

        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        OkHttpUtils.post(Urls.getMethodUrl("crm/GetVipCard"), map, callback);
    }
    /**
     * Derek
     * 查询会员卡券(会员查询模块)
     *
     * @param requestParam
     * @param callback
     */
    public static void QueryMemberCouponExcute(QueryMemberRequest requestParam, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("condType",requestParam.getCondType());
            Params_json.put("condValue",requestParam.getCondValue());
            Params_json.put("sktno",ErpCommonData.sktno);
            Params_json.put("serverBillId",requestParam.getServerBillId());
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        MessageLog.writeLog("消费查询卡券的serverBillId："+requestParam.getServerBillId());
        OkHttpUtils.post(Urls.getMethodUrl("crm/GetVipCoupon"), map, callback);
    }
    /**
     * 查询储值卡信息(会员查询模块)
     */
    public static void QueryCashCard(QueryMemberRequest requestParam, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("condType",requestParam.getCondType());
            Params_json.put("condValue",requestParam.getCondValue());
            Params_json.put("verifyCode",requestParam.getVerifyCode());
            Params_json.put("sktno",ErpCommonData.sktno);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("/crm/GetCashCard");
        OkHttpUtils.post(url, map, callback);
    }

    /**
     * 商品查询  单独接口
     */
    public  static void QueryGood(String goodsCode,OkHttpUtils.ResultCallback callback){
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("sktno",ErpCommonData.sktno);
            if (goodsCode.length() < GetConfigs.getGoodsCodeLength()){//自动补0
                goodsCode = CommonUtils.autoAddZero(goodsCode, GetConfigs.getGoodsCodeLength());
            }
            Params_json.put("barcode",goodsCode);
            Params_json.put("deptId",ErpCommonData.loadConfig.getCashierDeptId());
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        if(ErpCommonData.isOffline) {
            OfflineManager.QueryGood(Params_json, callback);
        }else {
            OkHttpUtils.post(Urls.getMethodUrl("order/querygoods"), map, callback);
        }
    }
    /**
     * 日报班报的网络请求
     *
     * @param callback
     */
    public static void ReportExecute(int skyid, OkHttpUtils.ResultCallback callback) {
        String code;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");// HH:mm:ss
        Date date = new Date(System.currentTimeMillis());
        map = new HashMap<>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("sktno",ErpCommonData.sktno);
            Params_json.put("bj",1);//1记账日期  0自然日
            Params_json.put("jzrq",simpleDateFormat.format(date));
            Params_json.put("personId",skyid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        if (skyid == -1) {
            code = null;
        } else {
            code = String.valueOf(skyid);
        }
        map.put("skyid", code);
        if(ErpCommonData.isOffline){
            OfflineManager.report(Params_json,callback);
        }else {
            OkHttpUtils.post(Urls.getMethodUrl("common/report"), map, callback);
        }
    }
    /**
     * 修改密码
     *
     * @param newPassword 新密码
     * @param
     * @param personId    操作员id
     * @param callback
     */
    public static void ModifyPasswordHttpEexcute(String newPassword,String oldPassword, String personId, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("personId",Integer.valueOf(personId));
            Params_json.put("password",newPassword);//CommonUtils.md5(newPassword).toUpperCase()
            Params_json.put("old_password",oldPassword);//CommonUtils.md5(oldPassword).toUpperCase()

        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("common/changepassword");
        OkHttpUtils.post(url, map, callback);
    }

    /**
     * 储值卡、优惠券、编码券核销接口
     * @param payData
     * @param callback
     */
    public static void ConsumeCrmPay(ConsumeCrmPayData payData, OkHttpUtils.ResultCallback callback){
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("orderno",payData.getOrderno());
            Params_json.put("guid",payData.getGuid());
            Params_json.put("code",payData.getCode());
            Params_json.put("type",payData.getType());
            Params_json.put("saleType",null);
            Params_json.put("yhkCard",payData.getYhkCard());
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        OkHttpUtils.post(Urls.getMethodUrl("payment/Consume"), map, callback);
    }

    /**
     * 软件更新
     *
     * @param versionCode
     * @param callback
     */
    public static void Updata(String versionCode, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("storeCode",ErpCommonData.storeCode);
            Params_json.put("sktno",ErpCommonData.sktno);
            Params_json.put("version", String.valueOf(versionCode));
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("common/getversion");
        OkHttpUtils.post(url, map, callback);
    }

    /**
     * 编码券查询
     * @param reqData
     * @param callback
     */
    public static void getCodedCouponList(QueryMemberRequest reqData, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("condType",reqData.getCondType());
        newMap.put("condValue",reqData.getCondValue());
        newMap.put("verifyCode",reqData.getVerifyCode());
        newMap.put("password",reqData.getPassword());
        newMap.put("codedCouponCode",reqData.getCodedCouponCode());
        newMap.put("codedCouponType",reqData.getCodedCouponType() +"");
        newMap.put("serverBillId",reqData.getServerBillId());
        newMap.put("cardCodeToCheck",reqData.getCardCodeToCheck());
        newMap.put("sktno",reqData.getSktno());
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        OkHttpUtils.post(Urls.getMethodUrl("crm/GetCodedCoupon"), map, callback);
    }

    public static void queryBuyCentNeedMoney(MoneyBuyCentData reqData, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("vipId",reqData.getVipId());
        newMap.put("needBuyCent",reqData.getNeedBuyCent());
        newMap.put("sktno",reqData.getSktno());
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        OkHttpUtils.post(Urls.getMethodUrl("crm/QueryBuyCentNeedMoney"), map, callback);
    }

    public static void procMoneyToCent(MoneyBuyCentData reqData, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("vipId",reqData.getVipId());
        newMap.put("vipCode",reqData.getVipId());
        newMap.put("buyCent",reqData.getNeedBuyCent());
        newMap.put("sktno",reqData.getSktno());
        newMap.put("cashMoney",reqData.getCashMoney());
        newMap.put("czkMoney",reqData.getCzkMoney());
        newMap.put("yhqMoney",reqData.getYhqMoney());
        newMap.put("personCode",reqData.getPersonCode());
        newMap.put("personName",reqData.getPersonName());
        newMap.put("personId",reqData.getPersonId());
        newMap.put("jlbh",reqData.getJlbh());
        newMap.put("oldSktno",reqData.getOldSktno());
        newMap.put("oldJlbh",reqData.getOldJlbh());
        newMap.put("payList",reqData.getPayList());
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        OkHttpUtils.post(Urls.getMethodUrl("crm/ProcMoneyToCent"), map, callback);
    }

    public static void QueryFood(String shopid, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("shopid",shopid);
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        OkHttpUtils.post(Urls.getMethodUrl("common/getCYList"), map, callback);
    }


    /**
     * 查询 餐桌列表
     *空置 = 0,
     就餐 = 1,
     脏台 = 2,
     预订 = 8,
     停用 = 9
     * @param callback
     * 当调用某个类的静态方法时
     */
    public static void  querytablesHttpEexcute(int status, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        baseMap.put("timestamp", DateUtils.getCurrentTime());
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("shopid",ErpCommonData.loadConfig.getShopId());
        newMap.put("status",status);
        String sortJsonStr = CommonUtils.sortStrNewJsonStr(newMap);
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url ="";
        url = Urls.getMethodUrl("common/getTableList");
        OkHttpUtils.post(url, map, callback);
    }

    /**
     * 更新桌子状态
     *
     * @param callback
     * 当调用某个类的静态方法时
     */
    public static void  updataTableStatusHttpEexcute(int shopid, int tableid,int tablestatus,OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        baseMap.put("timestamp", DateUtils.getCurrentTime());
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("shopid",shopid);
        newMap.put("id",tableid);
        newMap.put("status",tablestatus);
        String sortJsonStr = CommonUtils.sortStrNewJsonStr(newMap);
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url ="";
        url = Urls.getMethodUrl("common/changeCYTable");
        OkHttpUtils.post(url, map, callback);
    }

    /**
     *  预定修改
     * @param callback
     * 当调用某个类的静态方法时
     */
    public static void  reserveTableHttpEexcute(OrderfoodInput input, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        baseMap.put("timestamp", DateUtils.getCurrentTime());
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("shopid",input.getShopid());
        newMap.put("id",input.getId());
        newMap.put("name",input.getName());
        newMap.put("phone",input.getPhone());
        newMap.put("beginTime",input.getBeginTime());
        newMap.put("endTime",input.getEndTime());
        newMap.put("mealsCount",input.getMealsCount());
        String sortJsonStr = CommonUtils.sortStrNewJsonStr(newMap);
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url ="";
        url = Urls.getMethodUrl("common/reserveTable");
        OkHttpUtils.post(url, map, callback);
    }

    /**
     *  获取预定列表
     * @param callback
     * 当调用某个类的静态方法时
     */
    public static void  getReserveTableListHttpEexcute(boolean isfoodinfo, int tableId, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        baseMap.put("timestamp", DateUtils.getCurrentTime());
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("shopid",ErpCommonData.loadConfig.getShopId());
        if (isfoodinfo){
            newMap.put("tableId",tableId);
        }else {
            newMap.put("tableId",-1);//查预定列表传 餐桌默认-1

        }
        String sortJsonStr = CommonUtils.sortStrNewJsonStr(newMap);
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url ="";
        url = Urls.getMethodUrl("common/getReserveTableList");
        OkHttpUtils.post(url, map, callback);
    }


    /**
     *  获取预定列表
     * @param callback
     * 当调用某个类的静态方法时
     */
    public static void  cancelReserveTableHttpEexcute(String bookNo, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        baseMap.put("timestamp", DateUtils.getCurrentTime());
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("bookNo",bookNo);
        String sortJsonStr = CommonUtils.sortStrNewJsonStr(newMap);
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url ="";
        url = Urls.getMethodUrl("common/cancelReserveTable");
        OkHttpUtils.post(url, map, callback);
    }

    //石基支付
    public static void sjConsume(POS_JHRequest request, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<>();
        map.putAll(baseMap);
        JSONObject Params_json = new JSONObject();
        try {
            Params_json.put("interfaceId",request.getInterfaceId());
            Params_json.put("storeId",request.getStoreId());
            Params_json.put("tradeType",request.getTradeType());
            Params_json.put("buyerCode",request.getBuyerCode());
            Params_json.put("orderNo",request.getOrderNo());
            double moneyInt = MoneyUtils.getMoneyDoubleElement(request.getTotalFee());
            Params_json.put("totalFee",moneyInt + "");
            Params_json.put("outTradeNo",request.getOutTradeNo());
            Params_json.put("sktno",request.getSktno());
            Params_json.put("jlbh",request.getJlbh());
            Params_json.put("skfs",request.getSkfs());
//            Params_json.put("operator1",request.getOperator1());
            Params_json.put("channelID",request.getChannelID());
            if (!TextUtils.isEmpty(request.getAttach())){
                Params_json.put("attach",request.getAttach());
            }
            Params_json.put("refundNo",request.getRefundNo());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        map.put("Params_json",Params_json.toString());
        String url = Urls.getMethodUrl("interface/sjpay");
        OkHttpUtils.post(url, map, callback);
    }

    /**
     * 脱机更新
     *
     * @param callback
     */
    public static void updateOffline(List<P_GetOffline> list, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<>();
        map.putAll(baseMap);
        TreeMap<String, Object> Params_json = new TreeMap<String, Object>();
        try {
            Params_json.put("offlineList",list);
            // Params_json.put("downOneTableSign","1");
        } catch (Exception e) {
            e.printStackTrace();
        }
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(Params_json);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(Params_json);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        String url = Urls.getMethodUrl("common/getdownloadofflinedata");
        OkHttpUtils.post(url, map, callback);
    }

    /***
     * 脱机上传数据
     * @param mTicket
     * @param callback
     */
    public static void offlineUploadeData(TicketOffline mTicket, OkHttpUtils.ResultCallback callback) {
        map = new HashMap<String, Object>();
        map.putAll(baseMap);
        TreeMap<String, Object> newMap = new TreeMap<String, Object>();
        newMap.put("SktNo",mTicket.getSktNo());
        newMap.put("Jlbh",mTicket.getJlbh());
        newMap.put("OrderNo",mTicket.getOrderNo());
        newMap.put("TotalMoney",mTicket.getSaleMoney());
        newMap.put("TotalCount",mTicket.getGoodsList().size());
        newMap.put("TotalDiscount",mTicket.getTotalDiscount());
        newMap.put("TotalSKJE",mTicket.getSaleMoney());
        newMap.put("TotalDecDiscount",0);
        newMap.put("TotalFrontDiscount",0);
        newMap.put("TotalDecPreferential",0);
        newMap.put("ChangeMoney",0);
        newMap.put("OldOrderNo",mTicket.getOldOrderNo());
        newMap.put("StoreCode",mTicket.getStoreCode());
        newMap.put("SaleMoney",mTicket.getSaleMoney());
        newMap.put("Skyid",mTicket.getSkyid());
        newMap.put("Ddly",mTicket.getDdly());
        newMap.put("Jylx",mTicket.getJylx());
        newMap.put("OrderFunction",mTicket.getOrderFunction());
        newMap.put("Status",mTicket.getStatus());
        newMap.put("Jyjf",mTicket.getJyjf());
        newMap.put("Offline",true);
        newMap.put("KSSJ",mTicket.getKssj());
        newMap.put("SalerInfoList",mTicket.getSalerInfoList());
        newMap.put("SKYInfo",mTicket.getSkyInfo());
        newMap.put("GoodsList",mTicket.getGoodsList());
        newMap.put("PayList",mTicket.getPayList());
        String sortJsonStr =CommonUtils.sortStrNewJsonStr(newMap);//
        Map<String, Object> sortToStr =CommonUtils.sortStrNewToString(newMap);
        map.put("Params_json_sign",sortJsonStr);
        map.put("Params_json",sortToStr);
        OkHttpUtils.post(Urls.getMethodUrl("order/saveofflineorder"), map, callback);
    }
}

